Skip to content

refactor: keep walletId out of v1 activity payloads#117

Open
coreyphillips wants to merge 1 commit into
masterfrom
refactor/wallet-id-v1-payload-compat
Open

refactor: keep walletId out of v1 activity payloads#117
coreyphillips wants to merge 1 commit into
masterfrom
refactor/wallet-id-v1-payload-compat

Conversation

@coreyphillips

Copy link
Copy Markdown
Collaborator

Summary

Resolves #112. walletId was added directly to the activity models, which changed the v1 JSON schema without bumping the version. This restores v1 payload compatibility.

After weighing the issue's literal request (separate OnchainActivityV1/OnchainActivityV2 and LightningActivityV1/LightningActivityV2 structs), we kept the single-struct approach because it is strictly simpler here and meets every acceptance criterion. The reasoning:

  • Activities are stored as normalized SQLite columns, not whole JSON blobs, and wallet_id is already a first-class column with composite primary key (wallet_id, id). A versioned enum { V1, V2 } only earns its keep when you persist serialized blobs and must decode an unknown shape, which this crate never does.
  • The versioned-enum route would introduce the exact hazard the issue flags ("queries must still dedupe or normalize so callers do not see duplicate v1/v2 entries"). The single-struct approach cannot produce a duplicate: one row, wallet_id is a column, one canonical shape out.
  • The watch-only/walletId work has not shipped publicly, so there is no walletId-bearing production data to migrate. The only production format is v1 without walletId, which already decodes via serde defaults.

Approach

  • Default-wallet records omit walletId from their JSON via skip_serializing_if, keeping the original v1 payload byte-identical.
  • Records scoped to a non-default wallet keep walletId present, so the presence of the field is the version discriminator.
  • Old v1 JSON without walletId still decodes, defaulting to the built-in wallet.

This is applied to OnchainActivity, LightningActivity, ActivityTags, PreActivityMetadata, and TransactionDetails.

Acceptance criteria

  • walletId is not required on v1 activity payloads.
  • New wallet-scoped activities serialize with walletId.
  • Old v1 activity JSON without walletId decodes successfully.
  • Wallet-scoped APIs treat imported/migrated v1 activities as default-wallet activities.
  • Public queries do not return mixed or duplicate v1/v2 entries for the same logical activity.

Tests

New tests cover old v1 decode, v2 hardware-wallet activity creation, the wallet-scoped metadata payload rule, and mixed v1/v2 lookup, list, and search behavior for activities sharing the same raw id.

cargo test modules::activity: 178 passed, 0 failed. cargo clippy: clean for the activity module.

walletId was added directly to the activity models, which changed the v1
JSON schema without bumping the version. This restores v1 payload
compatibility without introducing separate V1/V2 model structs.

Default-wallet records now omit walletId from their JSON via
skip_serializing_if, keeping the original v1 payload byte-identical.
Records scoped to a non-default wallet keep walletId present, so the
presence of the field acts as the version discriminator. Old v1 JSON
without walletId still decodes, defaulting to the built-in wallet.

Storage already scopes activity identity by (walletId, id) with composite
primary keys, so lookup, list, search, tags, seen state, and transaction
details stay wallet-scoped and never return mixed or duplicate entries for
the same logical activity.

Tests cover old v1 decode, v2 hardware-wallet activity creation, the
wallet-scoped metadata payload rule, and mixed v1/v2 lookup, list, and
search behavior for activities sharing the same raw id.

Refs #112
@coreyphillips coreyphillips requested a review from ovitrif June 26, 2026 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: move walletId to v2 activity models

1 participant